package kr.hkit.androidcomplete02.ch12;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class Ch12_SpinnerTest extends Activity {
	ArrayAdapter<CharSequence> adspin;
	boolean mInitSpinner;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinnertest);

		Spinner spin = (Spinner) findViewById(R.id.ch12_myspinner);
		spin.setPrompt("과일을 고르세요.");

		adspin = ArrayAdapter.createFromResource(this, R.array.fruits,
				android.R.layout.simple_spinner_item);
		adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spin.setAdapter(adspin);

		spin.setOnItemSelectedListener(new OnItemSelectedListener() {
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				/*
				 * 초기화 시의 선택 제외시 if(mInitSpinner == false) { mInitSpinner =true;
				 * return; }
				 */
				Toast.makeText(Ch12_SpinnerTest.this,
						adspin.getItem(position) + "는 맛이다", Toast.LENGTH_SHORT)
						.show();
			}
			@Override
			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
	}
}
